public class HashBuck {
    static  class Node{
        public int key;
        public int value;
        public  Node next;


        public Node(int key, int value) {
            this.key = key;
            this.value = value;
        }
    }
    public Node[] array;
    public int usedSize;
    public  double lodeFactor=0.75;

    public HashBuck(){
        array=new Node[10];
    }

    public void put(int key,int val){
         int index=key %array.length;
         Node cur=  array[index];
         //1.遍历当前链表是否存在当前值
        while (cur!=null){
            if(cur.key==key){
                cur.value=val;
                return;
            }
            cur=cur.next;
        }
        //2.说明 没有当前值。此时进行 头插法
        Node node=new Node(key,val);
        node.next=array[index];
        array[index]=node;
        usedSize++;

        //3.
        if(lodeFactorCount()>=lodeFactor){
            //扩容

        }


    }
  private void resize(){
        Node[] newArray=new Node[array.length*2];
      for (int i = 0; i < array.length; i++) {
          Node cur=array[i];
          //开始遍历链表
          while (cur!=null){
          int newIndex=cur.key%newArray.length;
          //把数据存放在新的newIndex位置
              Node curN=cur.next;
              cur.next=newArray[newIndex];
              newArray[newIndex]=cur;
              cur=cur.next;
          }
      }
      array=newArray;
  }

    private  double lodeFactorCount(){
        return usedSize*1.0/array.length;
    }
    public  int get(int key){
        int index=key%array.length;
        Node cur=array[index];
        //1.遍历当前链表
        while(cur!=null){
            if(cur.key==key){
                return cur.value;
            }
            cur=cur.next;
        }
        return -1;
    }
}
